package cao.oschina.activity;

import android.material.widget.NavigationView;
import android.os.Bundle;
import android.view.View;

import cao.oschina.R;
import cao.oschina.app.AppContext;
import cao.oschina.widget.ToolBarView;


/**
 * ToolBarActivity
 * <p/>
 * Created by Haidy on 15/3/2.
 */
public abstract class ToolBarActivity extends lib.toolbar.activity.ToolBarActivity {

    private ToolBarView toolBarView;
    public AppContext app;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        app = (AppContext) getApplication();
        toolBarView = new ToolBarView(getBaseContext());
        setToolBar(toolBarView);
        toolBarView.setBackgroundColor(getResources().getColor(R.color.app_green));
        initView();
        initData();
    }

    /**
     * 初始化界面
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    @Override
    public void setTitle(CharSequence title) {
        toolBarView.setTitle(title);
    }

    /**
     * 配置返回
     */
    public void configBack() {
        toolBarView.getNavigationView().setType(NavigationView.NAV_BACK);
        toolBarView.getNavigationView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                activityPopAnim();
            }
        });
    }

    /**
     * 结束activity
     */
    public void finishActivity() {
        super.finish();
    }

    @Override
    public void finish() {
        super.finish();
        activityPopAnim();
    }

    /**
     * 打开新的activity动画
     */
    public void activityPushAnim() {
        overridePendingTransition(R.anim.activity_anim_push_in, R.anim.activity_anim_push_out);
    }

    /**
     * 关闭activity动画
     */
    public void activityPopAnim() {
        overridePendingTransition(R.anim.activity_anim_pop_in, R.anim.activity_anim_pop_out);
    }

}
